/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package me.crosswall.lib.coverflow;

import ohos.aafwk.ability.AbilitySlice;
import ohos.agp.components.AttrSet;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.ListContainer;
import ohos.app.Context;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;

import com.futuremind.recyclerviewfastscroll.FastScroller;


import java.util.ArrayList;
import java.util.List;

/**
 * Imgtestview
 *
 * @since 2021-03-23
 */
public class ListContainerView extends DirectionalLayout {
    private static final HiLogLabel LABEL_LOG = new HiLogLabel(HiLog.LOG_APP, 0x2021, "ListContainerView");
    List<SampleItem> list = null;
    private ListContainer listContainer;
    private FastScroller fastScroller;
    private  int mSum2 = 2;
    private  int mSum16 = 16;

    /**
     * ListContainerView
     *
     * @param context 去
     */
    public ListContainerView(Context context) {
        super(context);
        initview();
    }

    /**
     * ListContainerView
     *
     * @param context q
     * @param attrSet q
     */
    public ListContainerView(Context context, AttrSet attrSet) {
        super(context, attrSet);
        initview();
    }

    /**
     * ListContainerView
     *
     * @param context q
     * @param attrSet q
     * @param styleName q
     */
    public ListContainerView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        initview();
    }

    /**
     * initview
     */
    private void initview() {
        LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_listcontainerview, this, true);
        listContainer = (ListContainer) findComponentById(ResourceTable.Id_listcontainerview);
        fastScroller = (FastScroller) findComponentById(ResourceTable.Id_fast);
        fastScroller.setListContainer(listContainer);
        list = getData();
        SampleItemProvider sampleItemProvider = new SampleItemProvider(list, (AbilitySlice) getContext());
        listContainer.setItemProvider(sampleItemProvider);
    }

    private ArrayList<SampleItem> getData() {
        ArrayList<SampleItem> list1 = new ArrayList<>();
        for (int i = 0; i < mSum16; i++) {
            if (i % mSum2 == 0) {
                list1.add(new SampleItem("hello word"));
            } else {
                list1.add(new SampleItem("hello ohos"));
            }
        }
        return list1;
    }
}
